home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJLSR111.ZIP / libsrc / c / io / fread.c < prev    next >
C/C++ Source or Header  |  1993-06-28  |  1KB  |  53 lines

  1. /* This is file FREAD.C */
  2. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  3. ** these modifications are Coyright (C) 1993 DJ Delorie, 24 Kirsten Ave,
  4. ** Rochester NH, 03867-2954, USA.
  5. */
  6.  
  7. /*
  8.  * Copyright (c) 1980 Regents of the University of California.
  9.  * All rights reserved.  The Berkeley software License Agreement
  10.  * specifies the terms and conditions for redistribution.
  11.  */
  12.  
  13. #if defined(LIBC_SCCS) && !defined(lint)
  14. static char sccsid[] = "@(#)fread.c    5.2 (Berkeley) 3/9/86";
  15. #endif LIBC_SCCS and not lint
  16.  
  17. #include    <stdio.h>
  18.  
  19. fread(ptr, size, count, iop)
  20.     register void *ptr;
  21.     int size, count;
  22.     register FILE *iop;
  23. {
  24.     register int s;
  25.     int c;
  26.  
  27.     s = size * count;
  28.     while (s > 0) {
  29.         if (iop->_cnt < s) {
  30.             if (iop->_cnt > 0) {
  31.                 bcopy(iop->_ptr, ptr, iop->_cnt);
  32.                 ptr += iop->_cnt;
  33.                 s -= iop->_cnt;
  34.             }
  35.             /*
  36.              * filbuf clobbers _cnt & _ptr,
  37.              * so don't waste time setting them.
  38.              */
  39.             if ((c = _filbuf(iop)) == EOF)
  40.                 break;
  41.             *(char *)ptr++ = c;
  42.             s--;
  43.         }
  44.         if (iop->_cnt >= s) {
  45.             bcopy(iop->_ptr, ptr, s);
  46.             iop->_ptr += s;
  47.             iop->_cnt -= s;
  48.             return (count);
  49.         }
  50.     }
  51.     return (size != 0 ? count - ((s + size - 1) / size) : 0);
  52. }
  53.